package Vista;

import java.awt.EventQueue;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.SwingConstants;

import Vista.VistaJuego.VistaJuego;

import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Toolkit;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

@SuppressWarnings("serial")
public class MenuPrincipal extends JFrame {
	private JPanel contentPane;
	private JButton[] botones;
	
	private String robotElegido;


	public static void main(String[] args) {  
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					MenuPrincipal frame = new MenuPrincipal();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Crea el Menu
	 */
	public MenuPrincipal() {
		setResizable(false);
		setType(Type.UTILITY);
		setTitle( "Seleccione el Tipo de Robot" );
		setAlwaysOnTop( true );
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		Toolkit toolkit = Toolkit.getDefaultToolkit();
		Dimension scrnsize = toolkit.getScreenSize();
		int width = ( Double.valueOf( scrnsize.getWidth() ).intValue() ) / 4,
			height = ( Double.valueOf( scrnsize.getHeight() ).intValue() ) / 4;
		setBounds( 0, 0, width, height);
		setLocationRelativeTo( null );
		contentPane = new JPanel();
		setContentPane(contentPane);
		
		GridBagLayout gbl_contentPane = new GridBagLayout();
		contentPane.setLayout(gbl_contentPane);
		
		crearBotones();
		asignarOyentes_botones();
	}

	/**
	 * crearBotones.
	 */
	public void crearBotones() {
		int totalBotones = 2;
		botones = new JButton[ totalBotones ];
		GridBagConstraints gbc_botones = new GridBagConstraints();
		
		for ( int i = 0; ( i < botones.length ); i++ ) {
			botones[ i ] = new JButton();
			botones[ i ].setFocusable( false );
		}
		
		botones[ 0 ].setActionCommand( "Civil");
		botones[ 1 ].setActionCommand( "Militar" );
		botones[ 0 ].setMnemonic( 'c' );
		botones[ 1 ].setMnemonic( 'm' );
		botones[ 0 ].setIcon( new ImageIcon( MenuPrincipal.class.getResource( "/Civil II 6.png" ) ) );
		botones[ 1 ].setIcon( new ImageIcon( getClass().getResource( "/Militar I 6.png" ) ) );
		
		
		gbc_botones.insets.set( 0, 0, 0, 20 );
		for ( JButton boton : botones ) {
			boton.setText( boton.getActionCommand() );
			boton.setHorizontalTextPosition( SwingConstants.CENTER );
			boton.setVerticalTextPosition( SwingConstants.BOTTOM );
			contentPane.add( boton, gbc_botones );
		}
	}
	
	/**
	 * asignarOyentes_botones.
	 */
	public void asignarOyentes_botones() {
		for ( JButton boton : botones ) {
			boton.addActionListener( new oyenteBotones() );
		}
	}
	
	public class oyenteBotones implements ActionListener {
		
		/* (non-Javadoc)
		 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
		 */
		public void actionPerformed( ActionEvent e ) {
			setVisible( false );
			dispose();
			robotElegido = e.getActionCommand();
			
			VistaJuego frame = new VistaJuego( robotElegido );
			frame.setVisible(true);
		}
	}
}
